package com.itheima.web.manager;

import com.itheima.domain.db.Options;
import com.itheima.domain.db.Questionnaire;
import com.itheima.domain.db.SoulQuestion;
import com.itheima.service.db.OptionsService;
import com.itheima.service.db.QuestionnaireService;
import com.itheima.service.db.SoulQuestionService;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class HouTaiSoulManager {
    @DubboReference
    private QuestionnaireService questionnaireService;
    @DubboReference
    private SoulQuestionService soulQuestionService;
    @DubboReference
    private OptionsService optionsService;

    //分页查询题库
    public ResponseEntity findQuestionBank(Integer pageNum, Integer pageSize, String cid) {
        //调用rpc查询
        PageBeanVo pageBeanVo = questionnaireService.findQuestionBank(pageNum,pageSize,cid);
        return ResponseEntity.ok(pageBeanVo);
    }

    //远程调用保存
    public void addQuestionBank(Questionnaire questionnaire) {
        //rpc保存
        questionnaireService.addQuestionBank(questionnaire);
    }

    //查询答案
    public void deleteById(Integer id) {
        //rpc删除
        questionnaireService.deleteById(id);
    }

    //查询问题
    public ResponseEntity findQuestion(Integer pageNum, Integer pageSize, String bankId) {
        //rpc查询
        PageBeanVo pageBeanVo = soulQuestionService.findQuestion(pageNum,pageSize,bankId);
        return ResponseEntity.ok(pageBeanVo);
    }

    //根据id删题
    public void deleteQuestionById(Integer id) {
        //rpc删除
        soulQuestionService.deleteQuestionById(id);
    }

    //批量删题
    public void deleteMoreQuestion(Integer[] ids) {
        //rpc
        soulQuestionService.deleteMoreQuestion(ids);
    }

    //添加题目
    public void addQuestion(SoulQuestion soulQuestion) {
        //rpc
        soulQuestionService.addQuestion(soulQuestion);
    }

    //查询答案
    public ResponseEntity findSolution(Integer pageNum, Integer pageSize, Integer bankId) {
        PageBeanVo pageBeanVo = optionsService.findSolution(pageNum,pageSize,bankId);
        return ResponseEntity.ok(pageBeanVo);
    }

    //新增选项
    public void saveSolution(Options options) {
        //rpc
        optionsService.saveSolution(options);
    }

    //删指定id
    public void deleteSolutionById(Integer id) {
        //rpc
        optionsService.deleteSolutionById(id);
    }

    //删除多个选项
    public void deleteMoreSolution(Integer[] ids) {
        //rpc
        optionsService.deleteMoreSolution(ids);
    }
}
